import component, { ComType } from "../core/tool/component";
import { analysisIntent } from "../core/tool/baseScene";
import { mathType } from "../core/tool/face";
import { RankingService } from "../service/RankingService";
import { ModernRankingService } from "../service/ModernRankingService";
import { RankingType } from "../shared/face/enums";

/**
 * 排行榜组件 - 负责排行榜数据管理
 * 职责：
 * 1. 更新玩家排行榜数据
 * 2. 获取玩家排名信息
 * 3. 提供排行榜数据服务
 */
export default class ranking_component extends component {
    private _modernRankingService = this.getService<ModernRankingService>('ModernRankingService');
    
    constructor() {
        super();
        this.name = 'ranking_component';
    }

    init() {
        // 排行榜功能已移至场景中处理，不再需要注册指令
    }







    /**
     * 更新玩家排行榜数据
     * @param player 玩家对象
     */
    async updatePlayerRankingData(player: any) {
        try {
            // 更新所有排行榜数据
            await this._modernRankingService.updatePlayerRanking(player, RankingType.等级, 0);
            await this._modernRankingService.updatePlayerRanking(player, RankingType.金币, 0);
            await this._modernRankingService.updatePlayerRanking(player, RankingType.签到, 0);
            await this._modernRankingService.updatePlayerRanking(player, RankingType.战力, 0);
            
        } catch (error) {
            console.error('更新玩家排行榜数据失败:', error);
        }
    }

    /**
     * 获取玩家排名信息
     * @param playerId 玩家ID
     * @returns 排名信息
     */
    getPlayerRankingInfo(playerId: string): {
        levelRank: number;
        goldRank: number;
        signRank: number;
        powerRank: number;
    } {
        return {
            levelRank: this._modernRankingService.getPlayerRank(playerId, RankingType.等级),
            goldRank: this._modernRankingService.getPlayerRank(playerId, RankingType.金币),
            signRank: this._modernRankingService.getPlayerRank(playerId, RankingType.签到),
            powerRank: this._modernRankingService.getPlayerRank(playerId, RankingType.战力)
        };
    }
} 